#include "stdafx.h"
#include "TwoPointDrawElem.h"

CTwoPointDrawElem::CTwoPointDrawElem()
: m_TopLeft(0, 0)
, m_RightBottom(0, 0) 
{
	SetDefStyle();
}

CTwoPointDrawElem::CTwoPointDrawElem(CPoint b, CPoint e)
: m_TopLeft(b)
, m_RightBottom(e) 
{
	SetDefStyle();
}

CTwoPointDrawElem::CTwoPointDrawElem(int x1, int y1, int x2, int y2)
: m_TopLeft(x1, y1)
, m_RightBottom(x2, y2) 
{
	SetDefStyle();
}

void CTwoPointDrawElem::Clean() 
{
	m_TopLeft.x = 0;
	m_TopLeft.y = 0;
	m_RightBottom.x = 0;
	m_RightBottom.y = 0;
}

bool CTwoPointDrawElem::IsIncluded(const CRect &rect)
{
	return (m_TopLeft != m_RightBottom) && rect.PtInRect(m_TopLeft) && rect.PtInRect(m_RightBottom);
}

void CTwoPointDrawElem::SetDefStyle()
{
	m_Color = RGB(0, 0, 0);
	m_nWidth = 1;
	m_nStyle = PS_SOLID;
}


bool CLine::Draw(CDC &cdc)
{
	CPen penDef;
	penDef.CreatePen(m_nStyle, m_nWidth, m_Color);
	CPen * pOldDefPen = cdc.SelectObject(&penDef);
	cdc.MoveTo(m_TopLeft);
	cdc.LineTo(m_RightBottom);

	cdc.SelectObject(pOldDefPen);
	return true;
}



bool MSelectRect::Draw(CDC &cdc)
{
	CPen penDef;
	penDef.CreatePen(m_nStyle, m_nWidth, m_Color);
	CPen * pOldDefPen = cdc.SelectObject(&penDef);
	cdc.MoveTo(m_TopLeft);
	cdc.LineTo(m_RightBottom.x, m_TopLeft.y);
	cdc.LineTo(m_RightBottom);
	cdc.LineTo(m_TopLeft.x, m_RightBottom.y);
	cdc.LineTo(m_TopLeft);
	cdc.SelectObject(pOldDefPen);
	return true;
}